﻿using Aker.DevTeam;
using DevExpress.XtraGrid.Columns;
using Extensions;
using System;
using System.Collections.Generic;
using System.Data;

namespace Aker.Order
{
    public partial class CustomersAndFairVisitors : XForm
    {
        bool onlyFairVisitors = false;

        public CustomersAndFairVisitors()
        {
            InitializeComponent();
        }

        public CustomersAndFairVisitors(bool onlyFairVisitors)
        {
            InitializeComponent();
            this.onlyFairVisitors = onlyFairVisitors;
        }

        private void Customer_Load(object sender, EventArgs e)
        {
            DataTable dt = null;

            if (onlyFairVisitors)
            {
                //dt = Data.DM.ExecuteDataTable("GetFairVisitors");
                dt = Data.DB.Order;                
                gv.DoubleClick += gv_DoubleClick;
            }
              
            else
                dt = Data.DM.ExecuteDataTable("GetCustomersAndFairVisitors");

            gv.Init(dt);
            gv.MakeReadOnly();

            this.Text = gv.ViewCaption = Language.Customers.CustomerAndFairVisitors;
            if (AppSession.Language == "TR")
                gv.SetCaptions("Contact:Yetkili", "Brand:Marka", "eMail:e-posta", "Phone:Telefon", "Fax:Faks", "Address:Adres", "Country:Ülke", "Source:Kaynak");
            else
                gv.SetCaptions("eMail:e-mail");

            if (onlyFairVisitors)
            {
                List<string> fields = new List<string>() { "Brand","Contact","Email","Address","Phone","Fair","Season","Country","CarrierCustomerInfo"};
                foreach (GridColumn gc in gv.Columns)
                    gc.Visible = fields.Contains(gc.FieldName);

                gv.OptionsFind.AlwaysVisible = true;
                gv.OptionsFind.FindMode = DevExpress.XtraEditors.FindMode.Always;                
            }

            gv.BestFitColumns();

        }

        void gv_DoubleClick(object sender, EventArgs e)
        {
            SelectedRow = gv.GetFocusedDataRow();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        public DataRow SelectedRow { get; set; }
    }
}
